package com.power.sifa.approve.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.approve.model.Apl_thirdper;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 第三人 持久层(hibernate)
 */

public interface Apl_thirdperDao extends JpaRepository<Apl_thirdper, Serializable>, JpaSpecificationExecutor<Apl_thirdper>, Repository<Apl_thirdper, Serializable>, Apl_thirdperDaoCustom<Apl_thirdper, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Apl_thirdper s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

   @Query(" from Apl_thirdper s where  s.applyid = :applyid and s.saved = 3200")
   List<Apl_thirdper> getByApplyid(@Param("applyid") String applyid);


   @Query("select max(s.sortnum)  from Apl_thirdper s where  s.applyid = :applyid and s.saved = 3200")
   Integer queryMaxSotNumberApply(@Param("applyid") String applyid);


   @Query(value = "select distinct cardno, id, name FROM Apl_thirdper s where s.name like :name and s.saved = 3200  group by id ", nativeQuery = true)
   List<Map<String,Object>> searchCardNoByName(@Param("name") String name);

   @Query(" from Apl_thirdper s where s.id in (:ids) and s.saved = 3200")
   List<Apl_thirdper> getByIds(@Param("ids") List<String> ids);

   @Modifying
   @Transactional
   @Query(value = "update Apl_thirdper s set saved = 3200 where  s.applyid = :applyid  and s.saved = 3201", nativeQuery = true)
   void updateUnSaveThirder(@Param("applyid") String applyid);


   @Modifying
   @Transactional
   @Query(value = "delete  from Apl_thirdper s where s.applyid = :applyid  and saved = 3201", nativeQuery = true)
   void removeUnSaveThirder(@Param("applyid") String applyid);

}
